package com.rxt.thermopro.ui.chart

import android.content.Context
import android.widget.TextView
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.data.CandleEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.highlight.Highlight
import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Utils
import com.rxt.thermopro.R
import com.rxt.thermopro.app.LocalDataDao
import com.rxt.thermopro.bean.TempBean
import com.rxt.thermopro.bean.TempHumBean
import java.text.SimpleDateFormat
import java.util.*

class MyMarkerView(context: Context, layoutResource: Int,val list: MutableList<TempHumBean>) : MarkerView(context, layoutResource) {

    private var tvContent: TextView = findViewById(R.id.tvContent)
    val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm")

    override fun refreshContent(e: Entry?, highlight: Highlight?) {

//        if (e is CandleEntry) {
//            tvContent.text = "02:00PM  87°F " +
//                    Utils.formatNumber(e.high, 0, true) + "%"
//        } else {
//            tvContent.text = "02:00PM  87°F " + Utils.formatNumber(e!!.y, 0, true) + "%"
//        }

        if (e is CandleEntry) {
            tvContent.text = "02:00PM  87°F " +
                    Utils.formatNumber(e.high, 0, true) + "%"
        } else {
            val date = Date()
            date.time = list[(e?.x?:0).toInt()].tempTime.toLong()
            val timeStr = dateFormat.format(date)
            val str = timeStr.split(" ")[1]
//            val str = timeStr
            tvContent.text = "$str  ${e?.y}${LocalDataDao.INSTANCE.getTempUnit()}  ${list[(e?.x?:0).toInt()].humidityNum}%"
        }

        super.refreshContent(e, highlight)
    }

    override fun getOffset(): MPPointF {
        return MPPointF((-(width / 2)).toFloat(), (-height / 2).toFloat())
    }

}